home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / oberon / examples / xsum2.mod < prev   
Text File  |  1998-08-27  |  2KB  |  78 lines

  1. (*************************************************************************
  2.  
  3. :Program.    XSum2.mod
  4. :Contents.   sums up all bytes in a compressed or uncompressed file
  5. :Contents.   without reading the whole file at once into mem
  6. :Author.     Hartmut Goebel [hG] (ported to Oberon)
  7. :Language.   Oberon
  8. :Translator. Amiga Oberon V2.14
  9. :History.    V0.9, 09 Jan 1992 Hartmut Goebel [hG]
  10. :History.    V1.0, 11 Jul 1992 [hG] ·now more Oberon-like :-)
  11. :Date.       27 Jul 1992 12:19:31
  12.  
  13. *************************************************************************)
  14.  
  15. (* This is a typical read-and-process xpk application. Try it out... XSum a
  16.  * file, then compress it and XSum it again. The result should be the same.
  17.  *)
  18.  
  19. MODULE XSum2;
  20.  
  21. IMPORT
  22.   io,
  23.   arg := Arguments,
  24.   e   := Exec,
  25.   ol  := OberonLib,
  26.   s   := SYSTEM,
  27.   u   := Utility,
  28.   xpk := XpkMaster;
  29.  
  30. VAR
  31.   len, sum, i: LONGINT;
  32.   outBuf: POINTER TO ARRAY MAX(LONGINT)-1 OF CHAR;
  33.   errBuf: ARRAY xpk.errMsgSize+1 OF CHAR;
  34.   xfh: xpk.XpkFH;
  35.   Arg: e.STRING;
  36.  
  37. PROCEDURE end(text: ARRAY OF CHAR);
  38. BEGIN
  39.   io.WriteString(text); io.WriteLn;
  40.   HALT(10);
  41. END end;
  42.  
  43.  
  44. BEGIN
  45.   sum := 0; i := 0;
  46.  
  47.   IF arg.NumArgs() # 1 THEN end("Usage: XSum2 <filename>"); END;
  48.   arg.GetArg(1,Arg);
  49.  
  50.   IF 0 # xpk.OpenTags(xfh,
  51.            xpk.inName,      s.ADR(Arg),      (* The file name to be read              *)
  52.            xpk.getError,    s.ADR(errBuf),   (* A pointer to the error message buffer *)
  53.            xpk.passThru,    e.true,          (* Will pass through uncompressed data   *)
  54.            u.done)
  55.   THEN end(errBuf); END;
  56.  
  57.   ol.New(outBuf,xfh.fib.nLen);
  58.   IF outBuf = NIL THEN end("Out of memory"); END;
  59.  
  60.   len := xpk.Read(xfh, outBuf^, xpk.lenOneChunk);
  61.  
  62.   WHILE len > 0 DO
  63.     i := 0;
  64.     REPEAT
  65.       INC(sum,ORD(outBuf[i]));
  66.       INC(i);
  67.     UNTIL i = len;
  68.     len := xpk.Read(xfh, outBuf^, xpk.lenOneChunk);
  69.   END;
  70.  
  71.   IF (xpk.Close(xfh) #0) OR (len # 0) THEN end(errBuf); END;
  72.   io.WriteInt(sum,0); io.WriteLn;
  73.  
  74. CLOSE
  75.   ol.Dispose(outBuf);
  76.  
  77. END XSum2.
  78.